<?php
/**
 * 知也控制器
 */
class Index extends BaseAction
{
	private $_pagesize=10;//分页个数
	/**
	 * 初始化
	 */
	public function _init()
	{

	}

	/**
	 * 默认动作
	 */
	protected function _default()
	{

		#审核类型
		$type= $this->getParam('type');
		switch($type) {
			case 'pass':
				$nodatainfo =  '没有相匹配的知也信息';
				break;
			case 'no_pass':
				$nodatainfo = '没有相匹配的知也信息';
				break;
			default:
				$nodatainfo = '没有找到相匹配的知也信息';
		}

		#获取参数
		$key = $this->getParam('kw');

		#组合查询语句
		$strWhere = '';

		if(empty($type)){
			$strCheckState = '  checkState = 2';
		}else{
			#审核状态
			switch($type) {
				case 'pass':
					$checkState = 1;
					break;
				case 'no_pass':
					$checkState = 0;
					break;

			}

			$strCheckState = '  checkState = '.intval($checkState);

		}

		if(!empty($key)){
			$strWhereKey = ' and title like \'%'.$key.'%\''  ;
			//				$strWhereKey= "and title like '%$key%'";
		}

		if($key==0&&is_numeric($key)){
			$strWhereKey = ' and title like  \'%0%\' ';
		}






		#查询条件
		$strWhere = $strWhere.$strCheckState.$strWhereKey;

		#获取数据总数
		$total = DB::getRows('knows',$strWhere);


		/**分页操作 start**/
		$p = 1; //当前页码
		if (isset($_GET['p']) && is_numeric($_GET['p'])) {
			$p =intval($_GET['p']);
			if ($p<=1) {
				$p = 1;
			}
		}

		$totalPage = ceil($total/$this->_pagesize);//计算总页数
		$begin = ($p-1)*$this->_pagesize;//计算开始游标
		$limit = "$begin,$this->_pagesize";//计算分页


        if($totalPage){
		  $pageObj = new Dpage($total, $this->_pagesize, $p);
		  $pageCss = $pageObj->pageCss("1");
		  $pageform = $pageObj->outputPages(1,"<li>","</li>");
		}

		/**分页操作 end**/


		#获取数据信息
		$list = new publicGetDataModel();
		$listData = $list->getData($where = $strWhere,$limit = $limit,$fields = 'id,title,hot,img,content,checkState,dateline',$order = 'dateline',$table='knows');
		if(empty($listData)) {
			if (isset($key)) {
				$nodatainfo = '没有找到相匹配的知也信息';
			}
		}

		//内容中若有图片 去除图片
		if($listData){
			foreach($listData as $k=>$v){
				$listData[$k]['CONTENT']=strip_tags($listData[$k]['CONTENT']);

				//内容截取
				//$listData[$k]['subcontent']=Func::cnSubStr($listData[$k]['CONTENT'],162);
				$listData[$k]['subcontent']=$listData[$k]['CONTENT'];
			}
		}


		#模板赋值
		$now=time();
		$this->assign('now',$now);
		$this->assign('classify_list',$listData);

		$this->assign('pageCss',$pageCss);//分页样式
		$this->assign('pageform',$pageform);//分页标签
		$this->assign('type',$type);
		$this->assign('kw',$key);
		$this->assign('nodatainfo',$nodatainfo);

		$this->tpl_full_path('/front/knows/index');
	}




}
?>
